﻿Namespace Producto
    Public Class frmProductoSeleccionarPopup

        Public Property TextoBuscar As String
            Get
                Return Me.txtBuscar.Text
            End Get
            Set(ByVal value As String)
                Me.txtBuscar.Text = value
            End Set
        End Property

        Public Property Producto As Farmacia.Entity.Ventas.ComprobanteDetalle


       
        Public Sub Buscar()
            Dim obj As New Farmacia.Business.Producto.Producto
            Me.dgw_minedu.DataSource = obj.Listar(TextoBuscar, -1)

        End Sub

        Private Sub txtBuscar_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtBuscar.KeyDown
            If e.KeyCode = Keys.Enter Then
                Buscar()
            End If


        End Sub

    

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Buscar()
        End Sub

        Private Sub frmProductoSeleccionarPopup_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown
            LoadParameter()

            If TextoBuscar.Length > 0 Then
                Buscar()
            End If

        End Sub

        Public Sub LoadParameter()
            CargarTipo()
            'Listar()
        End Sub
        Public Sub CargarTipo()
            Dim obj As New Farmacia.Business.Producto.Tipo
            Dim ocol As Farmacia.Entity.Producto.TipoCol
            ocol = obj.Combo(True)
            Me.cbb_tipo.DisplayMember = "Nombre"
            Me.cbb_tipo.ValueMember = "TipoId"
            Me.cbb_tipo.DataSource = ocol
        End Sub


        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelar.Click
            Me.DialogResult = Windows.Forms.DialogResult.Cancel
            Me.Close()
        End Sub

        Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAgregar.Click
            SEleccionar()
        End Sub

        Public Sub Seleccionar()
            If Me.dgw_minedu.SelectedRows.Count = 1 Then
                Dim _productoid As Integer = Me.dgw_minedu.SelectedRows(0).Cells("col_productoid").Value.ToString
                Dim _productonombre As String = Me.dgw_minedu.SelectedRows(0).Cells("col_productonombre").Value.ToString
                Dim _productoprecio As String = Me.dgw_minedu.SelectedRows(0).Cells("col_precio").Value.ToString
                Dim _productostock As String = Me.dgw_minedu.SelectedRows(0).Cells("col_stock").Value.ToString

                Dim _ent As New Farmacia.Entity.Ventas.ComprobanteDetalle
                _ent.ProductoId = _productoid
                _ent.ProductoNombre = _productonombre
                _ent.PrecioBase = _productoprecio
                _ent.StockBase = _productostock

                Producto = _ent
                Me.DialogResult = Windows.Forms.DialogResult.OK
                Me.Close()

            Else
                Vichama.Configurations.Aplication.MessageBox.MensajeExclamation("Se debe selecionar solo un registro")
            End If
          

        End Sub

        Private Sub frmProductoSeleccionarPopup_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        End Sub
    End Class
End Namespace

